package com.faker.tools.util;

import lombok.extern.slf4j.Slf4j;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Map;

/**
 * <p>YmlUtil</p>
 *
 * <p>项目名称：gitlabSync</p>
 *
 * <p>注释:无</p>
 *
 * <p>Copyright: Copyright Faker(c) 2024/9/26</p>
 *
 * <p>公司: Faker</p>
 *
 * @author 淡梦如烟
 * @version 1.0
 * @date 2024/9/26 上午10:35
 */
@Slf4j
public class YmlUtil {

    /**
     * 加载yml文件
     *
     * @return Map<String, Object>
     * @throws FileNotFoundException FileNotFoundException
     */
    public static Map<String, Object> loadYml() throws FileNotFoundException {
        return loadYml("src/main/resources/application.yml");
    }

    /**
     * 加载yml文件
     *
     * @param path 文件路径
     * @return Map<String, Object>
     * @throws FileNotFoundException FileNotFoundException
     */
    public static Map<String, Object> loadYml(String path) throws FileNotFoundException {
        Yaml yaml = new Yaml();
        InputStream inputStream = new FileInputStream(new File(path));
        Map<String, Object> obj = yaml.load(inputStream);
        return obj;
    }
}
